import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 *  Proporciona un automovil para agregar obstaculos al escenario.
 * 
 * @author Asael Hernández García 
 * @version (a version number or a date)
 */
public class Obstaculo4 extends Obstaculo
{
    /**
     * Act - do whatever the Obstaculo4 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private SimpleTimer timer;
    private GreenfootSound choque;
    private int damage;
    
    public Obstaculo4(int damage)
    {
      this.damage = damage;
      timer = new SimpleTimer();
      timer.mark();
      resetPixels();
      choque = new GreenfootSound("choque.wav");
      choque.setVolume(getVol());
    }
    
    public void act()
    {
       mover();
       if(isTouching(Jugador.class)){
            choque.play();
            ((PistaAutomovil)getWorld()).addDamage(damage);
            ((PistaAutomovil)getWorld()).removeObs(this);
       }
       else
       if(timer.millisElapsed() > 400) {
       if(getImage().getWidth() >= 20 && getImage().getHeight()>= 20)
           disminuyeTam(getImage().getWidth()-getPixels(), getImage().getHeight()-getPixels());
       if(getY() <= getWorld().getHeight()/2 - getImage().getHeight()/2)    
           ((PistaAutomovil)getWorld()).removeObs(this); 
        
        timer.mark();
        addPixels();
       }
    }
}
